home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 175 / applic / yaps_t.s < prev    next >
Text File  |  1987-09-15  |  14KB  |  341 lines

  1.    ilabel TOS\TOS.L
  2. ;
  3. ;  Program Equates
  4. gpip      =     0
  5. len       =     4
  6. head      =     8
  7. tail      =     12
  8. gemdos    =     1
  9. bios      =     13
  10. xbios     =     14
  11. timeo     =     30
  12. keep      =    $31
  13. porta     =     14
  14. portb     =     15
  15. trap13    =    $B4
  16. timerC    =    $114
  17. savptr    =    $4A2
  18. hz_200    =    $4BA
  19. MFP       =    $FFFFFA01
  20. PSG       =    $FFFF8800
  21. ;
  22. ;Start of program for YAPS - timer C version
  23. ;
  24.         text
  25. yaps:   bra     ypstrm          ;Branch to temporary segment of program
  26. check:  dc.b    'YAPS_T.PRG'
  27. ;
  28. ; New Trap #13 Handler to intercept Printer Out and Status calls
  29. ;
  30. newtrp: move.l  savptr,A1       ;Save registers, sr, and return address
  31.         move.w  (sp)+,D0        ;  keeping a copy of sr to test for SUPER
  32.         move.w  D0,-(A1)        ;  vs. User mode
  33.         move.l  (sp)+,-(A1)
  34.         movem.l D3-D7/A3-A7,-(A1)
  35.         move.l  A1,savptr       ;Update save area pointer
  36.         btst    #13,D0          ;Get correct stack pointer
  37.         bne     newt10
  38.         move.l  usp,sp
  39. newt10: move.w  (sp),D0         ;Get call number
  40.         cmp.w   #3,D0           ;Check for "Conout"
  41.         bne     newt30
  42.         tst.w   2(sp)           ;If "Conout" then are we dealing with PRN: ?
  43.         bne     newt50
  44.         move.w  4(sp),D1        ;Get character to print and do it!
  45.         bsr     printo          ;jump to print character
  46. newt20: move.l  savptr,A1       ;Restore registers, sr, and return address
  47.         movem.l (A1)+,D3-D7/A3-A7
  48.         move.l  (A1)+,-(sp)
  49.         move.w  (A1)+,-(sp)
  50.         move.l  A1,savptr
  51.         rte
  52. newt30: cmp.w   #8,D0           ;Check for "Constat"
  53.         bne     newt50
  54.         tst.w   2(sp)           ;If "Constat" then are we dealing with PRN: ?
  55.         bne     newt50
  56.         move.w  sr,-(sp)        ;Stop Timer C while testing printer buffer
  57.         ori.w   #$0700,sr
  58.         moveq   #-1,D0
  59.         bsr     getptr          ;Check to see if there is room in the
  60.         move.l  tail(A0),D2     ;  Printer Spooler. If so, the printer
  61.         bsr     wrap            ;  must not be busy.
  62.         cmp.l   head(A0),D2
  63.         bne     newt40
  64.         moveq   #0,D0
  65. newt40: move.w  (sp)+,sr        ;Restart Timer C
  66.         bra     newt20
  67. newt50: move.l  savptr,A1       ;Restore registers, sr, and return address
  68.         movem.l (A1)+,D3-D7/A3-A7
  69.         move.l  (A1)+,-(sp)
  70.         move.w  (A1)+,-(sp)
  71.         move.l  A1,savptr
  72.         move.l  trpsve,A0       ;Not a Printer call - then just continue
  73.         jmp     (A0)            ;  on...
  74. ;
  75. ; Actual Timer C interrupt routine
  76. ; plus Printer Spooler out routine
  77. ;
  78. timer:  movem.l D0-D2/A0-A2,-(sp)
  79.         lea     MFP,A1          ;save registers and load pointers
  80.         btst    #0,gpip(A1)     ;Check if printer BUSY
  81.         bne     time10
  82.         bsr     getptr          ;Is there anything in buffer to print..
  83.         move.l  head(A0),D2
  84.         cmp.l   tail(A0),D2
  85.         beq     time10
  86.         bsr     wrap            ;Set up pointers to retrieve character
  87.         move.l  (A0),A2         ;  to print.
  88.         move.b  0(A2,D2.l),D1
  89.         bsr     notbus          ;Branch to specialized printing routine
  90.         move.l  D2,head(A0)
  91. time10: movem.l (sp)+,D0-D2/A0-A2
  92. timret: jmp     $FFFFFFFF       ;Chain to the Timer C Handler
  93. ;
  94. ; subroutine to send character to printer buffer OR printer
  95. ;
  96. printo: bsr     getptr          ;Set up pointers
  97.         move.l  head(A0),D2     ;If buffer already contains charcters
  98.         cmp.l   tail(A0),D2     ;  even if printer is now ready, store
  99.         bne     inbuff          ;  any new characters in the buffer!
  100. loop:   btst    #0,(A1)         ;If printer is BUSY, store characters
  101.         bne     inbuff          ;  in buffer.
  102. notbus: move    sr,-(sp)        ;This is the specialized routine to output
  103.         ori     #$0700,sr       ;  characters to a parallel printer. It has
  104.         movem.l D2-D5,-(sp)     ;  been optimized to pulse the strobe for
  105.         lea     PSG,A2          ;  2 microseconds, which is the limit of the
  106.         moveq   #portb,D2       ;  sound chip!
  107.         asl.l   #8,D2           ;Set up D2 to contain the character to print
  108.         add.b   D1,D2           ;  and the sound register to set up.
  109.         moveq   #portb,D5       ;Set up D5 to send a null character to print
  110.         asl.l   #8,D5           ;  and the sound register to set up.
  111.         moveq   #0,D0
  112.         move.b  #7,(A2)         ;Select the correct sound registers
  113.         move.b  (A2),D0
  114.         or.b    #$80,D0
  115.         move.b  #7,(A2)
  116.         move.b  D0,2(A2)
  117.         moveq   #porta,D3       ;Set up D3 to pulse the strobe high
  118.         asl.l   #8,D3
  119.         moveq   #0,D4           ;Set up D4 to pulse the strobe low
  120.         move.b  #porta,(A2)
  121.         move.b  (A2),D4         ;Get the current configuration of Port A
  122.         and.b   #$DF,D4         ;Finish setting up the contents of D3 to
  123.         move.b  D4,D3           ;  pulse the strobe
  124.         or.b    #$20,D4
  125.         movep.w D2,0(A2)        ;These next 4 statements actually write
  126.         movep.w D3,0(A2)        ;  the data to the Printer and pulse the
  127.         move.b  D4,2(A2)        ;  strobe
  128.         movep.w D5,0(A2)
  129.         moveq   #-1,D0          ;Return -1 as success
  130.         movem.l (sp)+,D2-D5
  131.         move    (sp)+,sr
  132.         rts
  133. inbuff: move.l  tail(A0),D2     ;First check to see if there is any more
  134.         bsr     wrap            ;  room in the printer buffer to store
  135.         cmp.l   head(A0),D2     ;  more characters
  136.         beq     inb100
  137. inb010: move.l  (A0),A1         ;If there is room, store the character and
  138.         move.b  D1,0(A1,D2.l)   ;  return -1 as success
  139.         move.l  D2,tail(A0)
  140.         moveq   #-1,D0
  141.         rts
  142. inb100: move.l  hz_200,D0       ;No room, then wait up to 30 seconds for the
  143.         add.l   #timeo*200,D0   ;  printer buffer to be cleared by the
  144. wait:   cmp.l   head(A0),D2     ;  Timer C interrupt
  145.         bne     inb010
  146.         cmp.l   hz_200,D0
  147.         bhi     wait
  148.         moveq   #0,D0           ;No luck, printer down - return 0
  149.         rts
  150. ;
  151. ;Routine to setup pointers
  152. ;
  153. getptr: lea     rec_io,A0
  154.         lea     MFP,A1
  155.         rts
  156. ;
  157. ;Routine to wrap pointers around buffer
  158. ;
  159. wrap:   addq.l  #1,D2
  160.         cmp.l   len(A0),D2
  161.         bcs     nowrap
  162.         moveq   #0,D2
  163. nowrap  rts
  164. ;
  165. ; Data Segment - nonvolatile
  166. ;
  167. rec_io: dc.l    ypstrm
  168. length: dc.l    0
  169.         dc.l    0
  170.         dc.l    0
  171. ;
  172. ; BSS Segment - nonvolatile
  173. ;
  174. trpsve: ds.l    1
  175. ;
  176. ; Temporary Program Start
  177. ;
  178. ypstrm: PRINTLINE tline         ;Show title of program
  179.         bsr     go_sup          ;Enter SUPER mode and test to see if the
  180.         sub.l   A2,A2           ;  Printer Spooler has already been installed
  181.         move.l  trap13(A2),A0
  182.         sub.l   #10,A0          ;Check for title of program in the 10 bytes
  183.         lea     check,A1        ;  preceeding the start of the TRAP #13 handler
  184.         moveq   #7,D1
  185. yps000: cmpm.b  (A1)+,(A0)+
  186.         bne     yps040
  187.         dbra    D1,yps000
  188.         bsr     go_use          ;return to use mode
  189.         PRINTLINE error5        ;  ask if user wishes to clear buffer,
  190. yps010: CONIN_WE                ;  then end program
  191.         and.b   #$5F,D0
  192.         cmpi.b  #'Y',D0
  193.         bne     yps020
  194.         CONOUT  D0
  195.         bsr     go_sup          ;To clear buffer, must first enter SUPER
  196.         move.w  sr,-(sp)        ;  mode to stop all interrupts, including
  197.         ori.w   #$0700,sr       ;  Timer C.  Then clear the "head" and
  198.         sub.l   A1,A1           ;  "tail" values of pointer to buffer.
  199.         move.l  trap13(A1),A0   ;Set up pointer to "head/tail"
  200.         add.l   #length-newtrp+4,A0
  201.         clr.l   (A0)
  202.         clr.l   4(A0)
  203.         move.w  (sp)+,sr        ;When done, start interrupts, get out of
  204.         bsr     go_use          ;  SUPER mode, and leave.
  205.         TERM
  206. yps020: cmpi.b  #'N',D0
  207.         beq     yps030
  208.         CONOUT  #7
  209.         bra     yps010
  210. yps030: CONOUT  D0
  211.         TERM
  212. yps040: bsr     go_use          ;Restore to user mode
  213.         move.l  4(sp),A0        ;Calculate size of program...
  214.         move.l  4(A0),D7        ;D7 will contain the end of the available TPA
  215.         sub.l   A0,D7           ;  minus the basepage address
  216.         move.l  #$100,D6        ;Size of base page
  217.         add.l   12(A0),D6       ;add TEXT length
  218.         add.l   20(A0),D6       ;add DATA length
  219.         add.l   28(A0),D6       ;add BSS  length
  220.         GETDTA                  ;ASK THE OPERATING SYSTEM FOR OUR FILE NAME
  221.         move.l  D0,A5           ;save address of current DTA
  222.         move.l  #buflen,A4      ;Set up pointer to size of buffer indicator
  223.         SFIRST  attrib,fname
  224.         tst     D0              ;Test for file found
  225.         beq     yap000
  226.         GETDIR  #0,drvbuf       ;If not, reset current drive to AUTO folder
  227.         CHDIR   autobf          ;  and look again.
  228.         SFIRST  attrib,fname
  229.         move.l  D0,D4
  230.         CHDIR   drvbuf
  231.         tst     D4
  232.         beq     yap000
  233.         PRINTLINE error1
  234.         bra     yap060          ;NOW CHECK FILENAME FOR SIZE OF PRINTER BUFFER
  235. yap000: moveq   #34,D0          ;Set up index into DTA for filename
  236.         moveq   #3,D1           ;Set up counter
  237.         moveq   #0,D3
  238.         moveq   #0,D5           ;This register will act as a flag for deleting
  239. yap010: moveq   #0,D2           ;  preceeding zero's
  240.         move.b  (A5,D0.w),D2    ;Start with the 4th character of the filename
  241.         cmpi.b  #'9',D2         ;Test to see if it is a number
  242.         bgt     yap050          ;Exit loop if not
  243.         cmpi.b  #'0',D2
  244.         blt     yap050
  245.         beq     yap020
  246.         moveq   #-1,D5
  247.         bra     yap030
  248. yap020: tst.w   D5
  249.         beq     yap040          ;Do not process preceeding zero's
  250. yap030: move.b  D2,(A4)+        ;Save number in buffer to print out later
  251.         subi.w  #$30,D2
  252.         mulu    #10,D3
  253.         add.w   D2,D3           ;D3 will contain the actual amount of memory
  254. yap040: addq.w  #1,D0           ; needed for the buffer in "K" units
  255.         dbra    D1,yap010
  256. yap050: cmpi.w  #0,D3
  257.         bne     yap070
  258.         PRINTLINE error2        ;No size of buffer in Program Name
  259. yap060  moveq   #32,D3          ;Use default Printer Buffer size of
  260.         move.w  #$3332,(A4)+    ;  32K
  261. yap070: move.b  #0,(A4)+
  262. yap080: move.l  D3,D5
  263.         moveq   #10,D0
  264.         lsl.l   D0,D5
  265.         add.l   D6,D5
  266.         cmp.l   D5,D7           ;Check to see if we have enough memory for
  267.         bgt     yap090          ;  requested PRINTER Spooler
  268.         PRINTLINE error3
  269.         PRINTLINE buflen        ;No, then abort set up
  270.         PRINTLINE error4
  271.         bsr     wte
  272.         TERM
  273. yap090: KBSHIFT #-1             ;Finally, check to see if user wants to
  274.         andi.w  #$6F,D0         ;  abort installation by holding down
  275.         beq     yap100          ;  either shift key, or control key,
  276.         PRINTLINE error6        ;  or alt key!
  277.         bsr     wte
  278.         TERM
  279. yap100: PRINTLINE mess01        ;Announce size of Printer Spooler set up
  280.         PRINTLINE buflen
  281.         PRINTLINE mess02
  282.         bsr     wte
  283.         moveq   #10,D0          ;Calculate total amount of printer buffer
  284.         lsl.l   D0,D3           ;  available to use
  285.         move.l  #ypsend,D0      ;Add in addition program space that will only
  286.         sub.l   #ypstrm,D0      ;  be used once!
  287.         add.l   D0,D3
  288.         move.l  D3,length       ;Save length of Printer Spooler needed
  289.         SETEXEC -1,#timerC/4    ;Set up link to timer C by
  290.         move.l  D0,timret+2     ;  chaining to old timer
  291.         SETEXEC timer,#timerC/4
  292.         SETEXEC newtrp,#trap13/4;Set up link to Trap #13
  293.         move.l  D0,trpsve
  294.         clr     -(sp)           ;Save needed buffer size
  295.         move.l  D5,-(sp)        ;and return
  296.         move    #keep,-(sp)
  297.         trap    #gemdos
  298.         TERM
  299. wte:    moveq   #10,D1          ;Routine to wait a bit to see messages
  300. wte10:  moveq   #-1,D0
  301. wte20:  dbra    D0,wte20
  302.         dbra    D1,wte10
  303.         rts
  304. go_sup: clr.l   -(sp)           ;Routine to enter SUPER mode, leaving return
  305. go_s10: move.w  #$20,-(sp)      ;  user stack pointer in D0
  306.         trap    #gemdos
  307.         addq.l  #6,sp
  308.         rts
  309. go_use: move.l  D0,-(sp)        ;Routine to return to USER mode
  310.         bra     go_s10
  311. ;
  312. ; Data Segment - volatile
  313. ;
  314. attrib: dc.w    0
  315. autobf: dc.b    '\AUTO\',0
  316. fname:  dc.b    'YAPS*.PRG',0
  317. tline:  dc.b    13,10,'"YET ANOTHER PRINTER SPOOLER"',13,10
  318.         dc.b    '      (timer C version)',13,10
  319.         dc.b    ' written by Phillip R. Poulos',13,10,10,0
  320. error1: dc.b    7,'** Original Program Name Not Found **',13,10,10,0
  321. error2: dc.b    7,'** Size For  Printer Spooler **',13,10
  322.         dc.b    '** Not Found In Program Name **',13,10,10,0
  323. error3: dc.b    7,'** Not Enough   MEMORY   Available **',13,10
  324.         dc.b    '**To Set Up A ',0
  325. error4: dc.b    'K Printer Spooler **',13,10
  326.         dc.b    '**       Installation Aborted!     **',13,10,0
  327. error5: dc.b    7,'**   YAPS is already running...   **',13,10
  328.         dc.b    '**      Installation Aborted!     **',13,10,10
  329.         dc.b    'Clear the printer spooler (Y or N)? ',0
  330. error6: dc.b    7,'** So you wish to abort installation! **',13,10
  331.         dc.b      '** See if I do you any favors soon... **',13,10,0
  332. mess01: dc.b    'Setting up a ',0
  333. mess02: dc.b    'K Printer Spooler!',13,10,0
  334.         align.w
  335. ;
  336. ; BSS Segment - volatile
  337. ;
  338. buflen: ds.b    10
  339. drvbuf: ds.b    64
  340. ypsend: end
  341.